<template>
  <view class="status_bar fs_16" :style="{
    backgroundColor: bgcolor,
    marginTop: marginTop + 'px',
    color: color,
  }">
    <view :style="{
      height: height + 'px',
      lineHeight: height + 'px',
      paddingTop: paddingTop + 'px',
      paddingBottom: paddingBottom + 'px',
    }" class="flex bar">
      <view @tap="goback" class="back">
        <uni-icons v-if="showBack" :type="iconType" :color="color" :size="iconsize" />
      </view>
      {{ title }}
      <view v-if="scarchCenter" :style="{
        width: searchwidth,
        height: searchheight + 'px',
        margin: searchmargin,
      }" class="search-box flex">
        <uni-icons type="search" color="#1D2541" size="24" />
        <input v-model="searchParam" placeholder="请输入关键词搜索" />
      </view>
      <view class="right">
        <slot name="right"></slot>
      </view>
    </view>
    <view v-if="scarchBottom" :style="{
      width: searchwidth,
      height: searchheight + 'px',
      margin: searchmargin,
    }" class="search-box flex">
      <uni-icons type="search" color="#1D2541" size="24" />
      <input @confirm="search" v-model="searchParam" placeholder="请输入关键词搜索" />
    </view>
  </view>
</template>

<script lang="ts" setup>
import { ref } from "vue";
const searchParam = defineModel();
let iconType: any = ref("left");
defineProps({
  searchwidth: {
    type: String,
    default: "200px",
  }, //搜索框宽度
  searchheight: {
    type: String,
    default: "32",
  }, //搜索框高度
  searchmargin: {
    type: String,
    default: "10px auto 0",
  }, //搜索框margin
  scarchCenter: {
    type: Boolean,
    default: false,
  }, //是否显示搜索框
  scarchBottom: {
    type: Boolean,
    default: false,
  }, //是否显示搜索框
  title: {
    type: String,
    default: "",
  },
  color: {
    type: String,
    default: "#1d2541",
  },
  iconsize: {
    type: String,
    default: "20",
  },
  bgcolor: {
    type: String,
    default: "",
  },
  showBack: {
    type: Boolean,
    default: false,
  }, //是否显示返回按钮
  path: {
    type: String,
    default: "",
  }, //页面路径
  paddingTop: {
    type: String,
    default: "12",
  },
  paddingBottom: {
    type: String,
    default: "12",
  },
  marginTop: {
    type: String,
    default: "0",
  },
  height: {
    type: String,
    default: "24",
  },
  barHeight: {
    type: String,
    default: "24",
  },
});
const emit = defineEmits(["search"]);
const search = () => {
  emit("search", searchParam.value);
};
const goback = () => {
  uni.navigateBack({
    delta: 1,
  });
};
</script>

<style lang="scss" scoped>
.status_bar {
  background-color: #fff;
  color: #1d2541;
  padding-bottom: 10px;
  position: relative;

  .bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .back {
    padding: 0 20px;
    position: absolute;
    left: 0;
  }

  .right {
    position: absolute;
    right: 0;
    padding: 0 20px;
  }

  .search-box {
    margin: auto;
    width: 200px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.08);
    background: rgb(245, 247, 249);
    padding-left: 10px;

    input {
      width: 95%;
    }
  }
}
</style>
